<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <nav>
      <!-- 一级菜单 -->
      <router-link to="/">发现音乐</router-link>
      <router-link to="/my">我的音乐</router-link>
      <router-link to="/friend">朋友</router-link>
    </nav>
    <!-- 一级路由对应组件渲染的容器 -->
    <router-view></router-view>
  </div>
  <script src="./vue.js"></script>
  <script src="./vue-router.min.js"></script>
  <script>
    // 一级路由对应的组件
    const Home = {
      template: `<div>
          <!-- 二级菜单 -->
          <router-link to="/tj">推荐</router-link>
          <router-link to="/top">排行榜</router-link>
          <router-link to="/order">歌单</router-link>
          <div>
            <!-- 二级路由对应组件渲染的容器 -->
            <router-view></router-view>  
          </div>
        </div>`
    }
    const My = {
      template: '<div>我的音乐网页内容</div>'
    }
    const Friend = {
      template: '<div>朋友网页内容</div>'
    }
    // 二级路由对应的组件
    const Tj = {
      template: '<div>推荐网页内容</div>'
    }
    const Top = {
      template: '<div>排行榜网页内容</div>'
    }
    const Order = {
      template: '<div>歌单网页内容</div>'
    }

    // 路由规则
    const routes = [
      {
        // children是用來实现嵌套路由的选项配置
        path: '/', component: Home, children: [
          { path: '/tj', component: Tj },
          { path: '/top', component: Top },
          { path: '/order', component: Order }
        ]
      },
      { path: '/my', component: My },
      { path: '/friend', component: Friend }
    ]
    // 初始化
    const router = new VueRouter({ routes })

    // 挂载
    new Vue({
      el: '#app',
      router
    })
  </script>
</body>

</html>